﻿<%@ Page Language="c#" CodeBehind="Fee.aspx.cs" AutoEventWireup="false" Inherits="UDS.SubModule.CM.Stat.FeePage" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
  <title>Fee</title>
  <uds:Style runat="server" Href="~/css/BasicLayout.css" />
  <script language="JavaScript" src="../../../Css/meizzDate.js"></script>
  <script language="javascript">
  //<!--
		function fillstring(str)
		{
			if(str.length==1)
			{
				str = "0" + str; 
			}
			return(str);
		}
		function quickseldate(type)
		{
			var begintime,endtime;
			var oneminute = 60*1000;
			var onehour   = 60*oneminute;
			var oneday    = 24*onehour;
			var oneweek   = 7*oneday;
			
			var todayDate = new Date();
			var date = todayDate.getDate();
			var month= todayDate.getMonth() +1;
			var year= todayDate.getYear();
			var day = todayDate.getDay();
			if(navigator.appName == "Netscape")
			{
				year = 1900 + year;
			}

			if(type=="day")
			{
				begintime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());
				endtime = begintime;
			}
			else if(type=="week")
			{
				var daytoMon = day-1;
				if(day==0) 
					daytoMon = 6;
				
				todayDate.setTime(todayDate.getTime()-daytoMon*oneday);
				date = todayDate.getDate();
				month= todayDate.getMonth() +1;
				year= todayDate.getYear();
				day = todayDate.getDay();
				
				begintime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());
				
				todayDate.setTime(todayDate.getTime()+6*oneday);
				
				date = todayDate.getDate();
				month= todayDate.getMonth() +1;
				year= todayDate.getYear();
				
				endtime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());
			}
			else if(type=="month")
			{
				var dateto1 = date-1;
				
				todayDate.setTime(todayDate.getTime()-dateto1*oneday);
				date = todayDate.getDate();
				month= todayDate.getMonth() +1;
				year= todayDate.getYear();
				day = todayDate.getDay();
				
				begintime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());
				
				todayDate.setMonth(month);
				todayDate.setTime(todayDate.getTime()-oneday);
				
				date = todayDate.getDate();
				month= todayDate.getMonth() +1;
				year= todayDate.getYear();
				
				endtime = year.toString() + "-" + fillstring(month.toString()) + "-" + fillstring(date.toString());

			}

			document.getElementById("tbx_begintime").value = begintime;
			document.getElementById("tbx_endtime").value = endtime;
		}
  //-->
  </script>
</head>
<body>
  <form id="Fee" method="post" runat="server">
    <table id="Table1" cellspacing="1" cellpadding="1" width="100%" border="1">
      <tr>
        <td align="right">
          <asp:DropDownList ID="ddl_order" runat="server">
            <asp:ListItem Value="client">按客户发生费用总量排列</asp:ListItem>
            <asp:ListItem Value="sellman">按销售人员费用总量排列</asp:ListItem>
          </asp:DropDownList>
        </td>
      </tr>
      <tr>
        <td>开始时间
          <asp:TextBox ID="tbx_begintime" onfocus="setday(this);" runat="server" ReadOnly="True" /><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" Display="Dynamic" ControlToValidate="tbx_begintime" />结束时间
          <asp:TextBox ID="tbx_endtime" onfocus="setday(this);" runat="server" ReadOnly="True" /><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="tbx_endtime" /><asp:RadioButton ID="rbtn_thisweek" onclick="quickseldate('week');" runat="server" GroupName="quickselect" Text="本周" /><asp:RadioButton ID="rbtn_thismonth" onclick="quickseldate('month');" runat="server" GroupName="quickselect" Text="本月" /><asp:Button ID="btn_OK" runat="server" Text="确定" /></td>
      </tr>
      <tr>
        <td>共 <asp:Literal ID="ltl_Client" runat="server" />位客户，共发生费用 <asp:Literal ID="ltl_Fee" runat="server" />元</td>
      </tr>
      <tr>
        <td>
          <asp:DataGrid ID="dgrd_clientfee" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="100%" CellPadding="3" BorderWidth="1px" BorderColor="#93BEE2">
            <AlternatingItemStyle BackColor="#E8F4FF" />
            <ItemStyle Font-Size="X-Small" />
            <HeaderStyle ForeColor="White" BackColor="#337FB2" />
            <Columns>
              <asp:BoundColumn DataField="ID" SortExpression="ID" HeaderText="编号" />
              <asp:TemplateColumn SortExpression="NAME" HeaderText="客户名称">
                <ItemTemplate>
                  <asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>' Target="_blank" NavigateUrl='<%# "../Client.aspx?ClientID="+DataBinder.Eval(Container,"DataItem.ID")%>' />
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="联系人">
                <ItemTemplate>
                  <a><%# GetLinkMan(((DataRowView)Container.DataItem).Row.GetChildRows("ClientLinkman_Staff")) %> </a>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="接触次数">
                <ItemTemplate>
                  <asp:Label runat="server" Text='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("Client_Contact").Length %>' />
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="发生费用">
                <ItemTemplate>
                  <asp:Label runat="server" Text='<%# GetFee(((DataRowView)Container.DataItem).Row.GetChildRows("Client_Contact")).ToString() %>' />
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="接触状态">
                <ItemTemplate>
                  <asp:HyperLink runat="server" Target="_blank" Text='<%# GetCurStatus(DataBinder.Eval(Container,"DataItem.Curstatus").ToString()) %>' NavigateUrl='<%# "../ClientContact.aspx?ClientID="+DataBinder.Eval(Container,"DataItem.ID")%>' />
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="添加人">
                <ItemTemplate>
                  <asp:Label runat="server" Text='<%# GetAddMan(((DataRowView)Container.DataItem).Row.GetChildRows("ClientAddMan_Staff")) %>' />
                </ItemTemplate>
              </asp:TemplateColumn>
            </Columns>
            <PagerStyle NextPageText="上一页" HorizontalAlign="Right" Mode="NumericPages" />
          </asp:DataGrid>
          <asp:DataGrid ID="dgrd_sellmanfee" runat="server" AllowPaging="True" AutoGenerateColumns="False" Width="100%" Visible="False" CellPadding="3" BorderWidth="1px" BorderColor="#93BEE2">
            <AlternatingItemStyle BackColor="#E8F4FF" />
            <ItemStyle Font-Size="X-Small" />
            <HeaderStyle ForeColor="White" BackColor="#337FB2" />
            <Columns>
              <asp:TemplateColumn HeaderText="销售人员">
                <ItemTemplate>
                  <%# ((DataRowView)Container.DataItem).Row.GetChildRows("StaffID_RealName")[0]["realname"].ToString() %>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="发生费用">
                <ItemTemplate>
                  <%# ((DataRowView)Container.DataItem)["Fee"].ToString()%>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="差旅">
                <ItemTemplate>
                  <%#  GetTravel(Int32.Parse(((DataRowView)Container.DataItem)["sellmanid"].ToString()),begintime,endtime)%>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="餐饮">
                <ItemTemplate>
                  <%#  GetFood(Int32.Parse(((DataRowView)Container.DataItem)["sellmanid"].ToString()),begintime,endtime)%>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="礼品">
                <ItemTemplate>
                  <%#  GetGift(Int32.Parse(((DataRowView)Container.DataItem)["sellmanid"].ToString()),begintime,endtime)%>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="公关">
                <ItemTemplate>
                  <%#  GetOuter(Int32.Parse(((DataRowView)Container.DataItem)["sellmanid"].ToString()),begintime,endtime)%>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="接触次数">
                <ItemTemplate>
                  <%#  GetContactTimes(Int32.Parse(((DataRowView)Container.DataItem)["sellmanid"].ToString()),begintime,endtime)%>
                </ItemTemplate>
              </asp:TemplateColumn>
              <asp:TemplateColumn HeaderText="接触客户数量">
                <ItemTemplate>
                  <%#  GetContactedClient(Int32.Parse(((DataRowView)Container.DataItem)["sellmanid"].ToString()),begintime,endtime)%>
                </ItemTemplate>
              </asp:TemplateColumn>
            </Columns>
            <PagerStyle Mode="NumericPages" HorizontalAlign="Right" />
          </asp:DataGrid>
        </td>
      </tr>
      <tr>
        <td align="center">&nbsp;</td>
      </tr>
    </table>
  </form>
</body>
</html>
